import { StorageManager } from '@vben-core/shared/cache';

import { requestClient } from '#/api/request';

const storageManager = new StorageManager({
  prefix: '',
  storageType: 'sessionStorage',
});
const rootCatalog = storageManager.getItem('rootCatalog') as string;
const userId = storageManager.getItem('userId') as string;
export namespace CatalogApi {
  export interface GetCatalogList {
    userId: string;
    catalogId: string;
  }
  export interface GetCatalogList {
    userId: string;
    catalogId: string;
  }
  export interface GetRootCatalog {
    parentId: string;
    userId: string;
  }
  export interface CreateCatalog {
    userId: string;
    parentCatalogId: string;
    catalogName: string;
  }
}

const getCatalogList = (getCatalogListObj: CatalogApi.GetCatalogList) => {
  return requestClient.get(
    `/dsc-systemMS/dsc-catalog/getChildren?catalogId=${rootCatalog}&userId=${userId}`,
    { params: getCatalogListObj },
  );
};
const getCatalogBreadCrumb = (catalogId: string) => {
  return requestClient.get(
    `/catalog/getCatalogBreadCrumb?catalogId=${catalogId}`,
  );
};

const createNewCatalog = (createNewCatalogObj: CatalogApi.CreateCatalog) => {
  return requestClient.post(
    'http://gateway:9527/dsc-systemMS/dsc-catalog',
    createNewCatalogObj,
  );
};
// 显示所有文件和文件夹
const getCatalogTree = (rootCatalog: string) => {
  return requestClient.get(
    `/dsc-systemMS/dsc-catalog/getOnlyCatalogTree/${rootCatalog}`,
  );
};

const getCatalogChildrenTree = (rootCatalogId: string) => {
  return requestClient.get(
    `/dsc-systemMS/dsc-catalog/getCatalogChildrenTree/${rootCatalogId}`,
  );
};
const getCatalogPwd = (catalogId: string) => {
  return requestClient.get(`/dsc-systemMS/dsc-catalog/pwd/${catalogId}`);
};
const getCatalogIdByRootAndFileId = (root: string, fileId: string) => {
  return requestClient.get(
    `/dsc-systemMS/dsc-catalog/getCatalogIdByFileIdAndRoot/${root}/${fileId}`,
  );
};

const getWorkflowModelCatalogId = (userId: string) => {
  return requestClient.get(
    `/dsc-systemMS/dsc-catalog/getWorkflowModelCatalogId/${userId}`,
  );
};

const getWorkflowModelCatalog = (catalogId: string) => {
  return requestClient.get(
    `/dsc-systemMS/dsc-catalog/getWorkflowModelCatalog/${catalogId}`,
  );
};

export default {
  getCatalogList,
  getCatalogBreadCrumb,
  createNewCatalog,
  getCatalogTree,
  getCatalogChildrenTree,
  getCatalogPwd,
  getCatalogIdByRootAndFileId,
  getWorkflowModelCatalogId,
  getWorkflowModelCatalog,
};
